home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / mousewheel / freewheel / main.c < prev    next >
C/C++ Source or Header  |  2000-03-08  |  4KB  |  161 lines

  1. #include <stdio.h>
  2.  
  3. #include <exec/types.h>
  4. #include <exec/ports.h>
  5. #include <intuition/intuition.h>
  6. #include <dos/dos.h>
  7.  
  8. #include <clib/exec_protos.h>
  9.  
  10. #include "Icon.h"
  11. #include "Prefs.h"
  12. #include "PrefsWin.h"
  13. #include "Cx.h"
  14. #include "CxCustom.h"
  15. #include "WheelMouse.h"
  16.  
  17. void *IntuitionBase,*LayersBase,*CxBase;
  18. void *IconBase,*GfxBase,*GadToolsBase;
  19. struct MsgPort *ReplyPort;
  20.  
  21. struct CxContext *MyCx;
  22. struct WheelMouseContext *MyWM;
  23. struct PrefsGroup *MyPrefs;
  24. struct PrefsWinContext *MyPrefsWin;
  25.  
  26.  
  27. void CxShowCallback(struct CxContext *cx)
  28. {
  29.   struct PrefsWinContext *pwc=cx->UserData;
  30.   if(pwc)
  31.   {
  32.     pwc->Show(pwc);
  33.   }
  34. }
  35.  
  36.  
  37. void CxHideCallback(struct CxContext *cx)
  38. {
  39.   struct PrefsWinContext *pwc=cx->UserData;
  40.   if(pwc)
  41.   {
  42.     pwc->Hide(pwc);
  43.   }
  44. }
  45.  
  46.  
  47. char *Main_Setup()
  48. {
  49.   if(!(IntuitionBase=OpenLibrary("intuition.library",37)))
  50.     return("Can't open intuition.library");
  51.   if(!(LayersBase=OpenLibrary("layers.library",37)))
  52.     return("Can't open intuition.library");
  53.   if(!(CxBase=OpenLibrary("commodities.library",37)))
  54.     return("Can't open commodities.library");
  55.   if(!(IconBase=OpenLibrary("icon.library",37)))
  56.     return("Can't open icon.library");
  57.   if(!(GfxBase=OpenLibrary("graphics.library",37)))
  58.     return("Can't open graphics.library");
  59.   if(!(GadToolsBase=OpenLibrary("gadtools.library",37)))
  60.     return("Can't open gadtools.library");
  61.  
  62.   if(!(ReplyPort=CreateMsgPort()))
  63.     return("Can't create message port");
  64.  
  65.   if(!(Icon_Setup()))
  66.     return("Problems with the icon!");
  67.  
  68.   if(!(MyPrefs=Prefs_GetGroup("FreeWheel.cfg")))
  69.     return("Problems with prefs!");
  70.  
  71.   if(!(MyPrefsWin=PrefsWin_Create(MyPrefs)))
  72.     return("Can't create User Interface!");
  73.  
  74.   if(!(MyWM=WheelMouse_Create()))
  75.     return("Can't create WheelMouse Context");
  76.  
  77.   if(!(MyCx=CxContext_Create("FreeWheel",
  78.                              "Scrolling with WheelMice - 1.1",
  79.                              "© 1999 - Alastair M. Robinson",MyPrefsWin)))
  80.     return("Can't create CxContext!");
  81.  
  82.   if(!(MyCx->SetCustom(MyCx,CxCustomRoutine)))
  83.     return("Can't create CxCustom object!");
  84.  
  85.   MyCx->ShowCallback=CxShowCallback;
  86.   MyCx->HideCallback=CxHideCallback;
  87.  
  88.   return(NULL);
  89. }
  90.  
  91.  
  92. void Main_Cleanup()
  93. {
  94.   if(MyCx)
  95.     MyCx->Dispose(MyCx);
  96.   MyCx=NULL;
  97.  
  98.   if(MyWM)
  99.     MyWM->Dispose(MyWM);
  100.   MyWM=NULL;
  101.  
  102.   if(MyPrefsWin)
  103.     MyPrefsWin->Dispose(MyPrefsWin);
  104.   MyPrefsWin=NULL;
  105.  
  106.   if(MyPrefs)
  107.     MyPrefs->Dispose(MyPrefs);
  108.   MyPrefs=NULL;
  109.  
  110.   Icon_Cleanup();
  111.  
  112.   if(ReplyPort)
  113.     DeleteMsgPort(ReplyPort);
  114.   ReplyPort=NULL;
  115.  
  116.   if(GadToolsBase) CloseLibrary(GadToolsBase); GadToolsBase=NULL;
  117.   if(GfxBase) CloseLibrary(GfxBase); GfxBase=NULL;
  118.   if(IconBase) CloseLibrary(IconBase); IconBase=NULL;
  119.   if(CxBase) CloseLibrary(CxBase); CxBase=NULL;
  120.   if(IntuitionBase) CloseLibrary(IntuitionBase); IntuitionBase=NULL;
  121.   if(LayersBase) CloseLibrary(LayersBase); LayersBase=NULL;
  122. }
  123.  
  124.  
  125. int main()
  126. {
  127.   char *error;
  128.   if(error=Main_Setup())
  129.   {
  130.     printf("Error: %s\n",error);
  131.   }
  132.   else
  133.   {
  134.     BOOL cont=TRUE;
  135.     unsigned long sigs;
  136.  
  137.     MyWM->WindowMode=MyPrefs->GetLong(MyPrefs,"WindowMode",OverWindow);
  138.     MyWM->MMBMode=MyPrefs->GetLong(MyPrefs,"MMBMode",Ignore);
  139.     MyWM->FourthButtonMode=MyPrefs->GetLong(MyPrefs,"FourthMode",Ignore);
  140.     MyWM->MouseSpeedX=MyPrefs->GetLong(MyPrefs,"XMouseSpeed",100);
  141.     MyWM->MouseSpeedY=MyPrefs->GetLong(MyPrefs,"YMouseSpeed",100);
  142.     MyWM->ClickToFront=MyPrefs->GetLong(MyPrefs,"ClickFront",TRUE);
  143.     MyWM->ClickToBack=MyPrefs->GetLong(MyPrefs,"ClickBack",FALSE);
  144.     MyCx->SetHotKey(MyCx,MyPrefs->GetString(MyPrefs,"Hot Key","ctrl alt f"));
  145.  
  146.     while(cont)
  147.     {
  148.       sigs=SIGBREAKF_CTRL_C|MyCx->Signals|MyWM->Signals|MyPrefsWin->Signals;
  149.       sigs=Wait(sigs);
  150.       if(sigs&SIGBREAKF_CTRL_C)
  151.         cont=FALSE;
  152.       cont&=MyCx->Handle(MyCx,sigs);
  153.       cont&=MyWM->Handle(MyWM,sigs);
  154.       cont&=MyPrefsWin->Handle(MyPrefsWin,sigs);
  155.     }
  156.   }
  157.   Main_Cleanup();
  158.   return(0);
  159. }
  160.  
  161.